<template>
    <el-dialog custom-class="form-dialog" :title="title" :visible.sync="dialogVisible" :close-on-click-modal="false" width="800px" v-loading="loading" destroy-on-close
        :before-close="handleClose">
        <!-- 表单内容 -->
        <div class="form-dialog-content-box">
            <el-form :model="form" label-width="100px" :rules="rules" ref="ruleForm" :size="size">
                <el-form-item label="接口路径：" prop="path">
                    <el-input v-model="form.path" :size="size"></el-input>
                </el-form-item>
                <el-form-item label="描述：" prop="description">
                    <el-input v-model="form.description" :size="size"></el-input>
                </el-form-item>
                <el-form-item label="忽略登录：" prop="ignoreToken">
                    <el-switch v-model="form.ignoreToken" :active-value="1" :inactive-value="0" @change="onIgnoreTokenChange"></el-switch>
                </el-form-item>
                <el-form-item label="忽略权限：" prop="ignorePermission">
                    <el-switch v-model="form.ignorePermission" :active-value="1" :inactive-value="0" :disabled="form.ignoreToken == 1"></el-switch>
                </el-form-item>
            </el-form>
        </div>
        <!-- 提交区域 -->
        <span slot="footer" class="dialog-footer">
            <el-button @click="handleCancelBtn" :size="size">取 消</el-button>
            <el-button type="primary" @click="handleSubmitBtn" :size="size">确 定</el-button>
        </span>
    </el-dialog>
</template>

<script>
//引入混入逻辑
import mixin from '@/mixins/form'
export default {
    name: "formDialog",
    mixins: [mixin],
    props: {
        title: {
            type: String,
            default: "新增"
        }
    },
    data() {
        return {
            form: {
                id: "",
                path: "",
                description: "",
                ignoreToken: 0,//状态 1启用 0停用
                ignorePermission: 1,//状态 1启用 0停用
            },//表单数据

            rules: {
                path: [
                    { required: true, message: '请输入接口路径', trigger: 'blur' },
                ],
            },//表单验证规则
        }
    },
    methods: {
        //忽略token开关切换
        onIgnoreTokenChange(){
            //如果是开启状态，则连同权限开关一起打开
            if(this.form.ignoreToken == 1){
                this.form.ignorePermission = 1
            }
        }
    }
}
</script>

<style scoped lang="scss">
.form-dialog-content-box {
    
}
</style>